#include"Camera.h"

/*************************************************************************************/

int Camera::numofcameras;

/*************************************************************************************/

void Camera::Proceed()
{
	if(actangle*180.0f/PI <= toangle && actangle*180.0f/PI >= fromangle)
		actangle += velocity*PI/180.0f;
	else
	{
		velocity *= -1;
		actangle += velocity*PI/180.0f ;//+ (velocity/abs(velocity))*PI/180.0f;
	}

	RenderCamera();
}

/*************************************************************************************/

void Camera::RenderCamera()
{
	GLfloat x1,y1, x2,y2, x3,y3, x4,y4;
	glColor3f(0.1,0.1,0.1);
	x1 = -(-5.0f)*sin(actangle) + x;//x*cos(actangle) 
	y1 =  (-5.0f)*cos(actangle) + y;//x*sin(actangle) +

	x2 = (20.0f)*cos(actangle) - -5.0f*sin(actangle) + x;
	y2 = (20.0f)*sin(actangle) + -5.0f*cos(actangle) + y;

	x3 = (20.0f)*cos(actangle) - (5.0f)*sin(actangle) + x;
	y3 = (20.0f)*sin(actangle) + (5.0f)*cos(actangle) + y;

	x4 = -(5.0f)*sin(actangle) + x;//x*cos(actangle) 
	y4 =  (5.0f)*cos(actangle) + y;//x*sin(actangle) +
	
	glBegin(GL_POLYGON);
	{
		glVertex3f(x1, y1, z);
		glVertex3f(x2, y2, z);
		glVertex3f(x3, y3, z);
		glVertex3f(x4, y4, z);
	}
	glEnd();

	
	glColor4f(0.3,0.3,0.3,0.5);
	glBegin(GL_POLYGON);
	{
		//promien rozchodzi sie z pktu na poczatku (20,0) i ma dlugosc sightlen, rozwartosc - innerangle
		//x1, y1 - poczatkowe polozenie danego punktu, x2,y2 - polozenie po obrocie
		for(int i = 1; i < 50; i++)
		{
			x1 = sightlen*cos(((i*(innerangle/50.0)) - innerangle/2.0)*PI/180.0);
			y1 = sightlen*sin(((i*(innerangle/50.0)) - innerangle/2.0)*PI/180.0);
			x2 = x1*cos(actangle) - y1*sin(actangle) + x;
			y2 = x1*sin(actangle) + y1*cos(actangle) + y;
			glVertex3f(x2,y2,z); //0.04 bo polozenie ludzika to 0.05 a ma byc promien pod
		}
		x1 = 20.0;
		y1 = 0.0;
		x2 = x1*cos(actangle) + x;
		y2 = x1*sin(actangle) + y;

		glVertex3f(x2,y2,z);
	}
	glEnd();
	glColor3f(0.5,0.5,0.5);

}

/*************************************************************************************/